﻿using BCDto.TMS.MoveHouseConfig.MoveHouseConfig;
using BCDto.TMS.MoveHouseConfig.MoveHouseConfig.MoveHouseConfigRequest;
using BCService.TMS.MoveHouseConfig.MoveHouseConfig;
using BCTMSRESTful.Configs;
using BCTMSRESTful.Controllers.Management;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Net;

namespace BCTMSRESTful.Controllers.Management.TMS.MoveHouseConfig
{
    /// <summary>
    /// 搬家配置
    /// </summary>
    [Route("api/v1/sim/[controller]")]
    [ApiExplorerSettings(GroupName = "TMSAdmin")]
    public class MoveHouseConfigController : ManagementBaseController
    {
        private readonly IMoveHouseConfigService moveHouseConfigService;
        public MoveHouseConfigController(IMoveHouseConfigService moveHouseConfigService)
        {
            this.moveHouseConfigService = moveHouseConfigService;
        }

        /// <summary>
        /// 创建搬家配置
        /// </summary>
        /// <param name="requestDto">搬家配置信息</param>
        /// <response code="201">创建搬家配置</response>
        /// <returns></returns>
        [HttpPost]
        [Log("创建搬家配置")]
        [ProducesResponseType(typeof(MoveHouseConfigViewDto), 200)]
        public IActionResult Create([FromBody] MoveHouseConfigRequestDto requestDto)
        {
            var result = this.moveHouseConfigService.Create(requestDto, this.Admin);
            return this.Ok(result);
        }

        /// <summary>
        /// 获取搬家配置(只查询当前id的搬家设置信息,不查询子级)
        /// </summary>
        /// <param name="moveHouseConfigId">搬家配置id</param>
        /// <returns></returns>
        [HttpGet("{move_house_config_id}")]
        [ProducesResponseType(typeof(MoveHouseConfigViewDto), 200)]
        public IActionResult GetSingle([FromRoute(Name = "move_house_config_id")] long moveHouseConfigId)
        {
            var result = this.moveHouseConfigService.GetSingle(moveHouseConfigId);
            return this.Ok(result);
        }

        /// <summary>
        /// 获取二级搬家配置
        /// </summary>
        /// <param name="isEnable">是否可用</param>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(IEnumerable<MoveHouseConfigViewDto>), 200)]
        public IActionResult GetAllSecondList([FromQuery(Name = "is_enable")] bool? isEnable)
        {
            var result = this.moveHouseConfigService.GetAllSecondList(isEnable);
            return this.Ok(result);
        }

        /// <summary>
        /// 获取搬家配置
        /// </summary>
        /// <param name="isEnable">是否可用</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(IEnumerable<MoveHouseConfigViewDto>), 200)]
        public IActionResult GetAllList([FromQuery(Name = "is_enable")] bool? isEnable)
        {
            var result = this.moveHouseConfigService.GetAllList(isEnable, 0);
            return this.Ok(result);
        }

        /// <summary>
        /// 获取搬家配置
        /// </summary>
        /// <param name="isEnable">是否可用</param>
        /// <param name="moveHouseConfigId">搬家设置id</param>
        /// <returns></returns>
        [HttpGet("[action]/{move_house_config_id}")]
        [ProducesResponseType(typeof(IEnumerable<MoveHouseConfigViewDto>), 200)]
        public IActionResult GetList([FromQuery(Name = "is_enable")] bool? isEnable,
            [FromRoute(Name = "move_house_config_id")] long moveHouseConfigId)
        {
            var result = this.moveHouseConfigService.GetList(moveHouseConfigId, isEnable, 0);
            return this.Ok(result);
        }

        /// <summary>
        /// 删除搬家配置
        /// </summary>
        /// <param name="moveHouseConfigId">搬家设置id</param>
        /// <returns></returns>
        [HttpDelete("{move_house_config_id}")]
        [ProducesResponseType(typeof(NoContentResult), 200)]
        public IActionResult Delete([FromRoute(Name = "move_house_config_id")] long moveHouseConfigId)
        {
            _ = moveHouseConfigService.Delete(moveHouseConfigId,this.Admin);
            return NoContent();
        }

        /// <summary>
        /// 设置搬家分类图片
        /// </summary>
        /// <param name="moveHouseConfigId">搬家设置id</param>
        /// <param name="requestDto">分类图片</param>
        /// <returns></returns>
        [HttpPut("[action]/{move_house_config_id}")]
        [ProducesResponseType(typeof(bool), 200)]
        public IActionResult UpdatePhoto([FromRoute(Name = "move_house_config_id")] long moveHouseConfigId,
            [FromBody] MoveHouseConfigPhotoRequestDto requestDto)
        {
            var result = moveHouseConfigService.UpdatePhoto(moveHouseConfigId, requestDto, this.Admin);
            return this.Ok(result);
        }


        /// <summary>
        /// 设置搬家设置是否可用
        /// </summary>
        /// <param name="moveHouseConfigId">搬家设置id</param>
        /// <param name="enabled">是否可用</param>
        /// <returns></returns>
        [HttpPut("[action]/{move_house_config_id}/{enabled}")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult UpdateEnabled([FromRoute(Name = "move_house_config_id")] long moveHouseConfigId, 
            [FromRoute(Name = "enabled")] bool enabled)
        {
            if (enabled)
                moveHouseConfigService.Enabled(moveHouseConfigId, this.Admin);
            else
                moveHouseConfigService.Disabled(moveHouseConfigId, this.Admin);
            return NoContent();
        }
    }
}
